﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using AssetManageSystem.Model.OrgManage;


namespace AssetManageSystem.ViewModel.OrgManage.UserVMs
{
    public partial class UserListVM : BasePagedListVM<User_View, UserSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("User", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "OrgManage", dialogWidth: 800),
                this.MakeStandardAction("User", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "OrgManage"),
            };
        }


        protected override IEnumerable<IGridColumn<User_View>> InitGridHeader()
        {
            return new List<GridColumn<User_View>>{
                this.MakeGridHeader(x => x.UserName),
                this.MakeGridHeader(x => x.UserSex),
                this.MakeGridHeader(x => x.UserPhone),
                this.MakeGridHeader(x => x.DepName_view),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<User_View> GetSearchQuery()
        {
            var query = DC.Set<User>()
                .CheckContain(Searcher.UserName, x=>x.UserName)
                .CheckEqual(Searcher.UserSex, x=>x.UserSex)
                .CheckContain(Searcher.UserPhone, x=>x.UserPhone)
                .CheckEqual(Searcher.UserDepId, x=>x.UserDepId)
                .Select(x => new User_View
                {
				    ID = x.ID,
                    UserName = x.UserName,
                    UserSex = x.UserSex,
                    UserPhone = x.UserPhone,
                    DepName_view = x.UserDep.DepName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class User_View : User{
        [Display(Name = "部门名称")]
        public String DepName_view { get; set; }

    }
}
